package cn.com.aiton.educenter.schedule;

import cn.com.aiton.educenter.entity.PestsProject;
import cn.com.aiton.educenter.service.PestsControlService;
import cn.com.aiton.educenter.service.PestsProjectService;
import cn.com.aiton.educenter.service.PestsTrapService;
import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class ScheduleTask {

    @Autowired
    private PestsProjectService service;

    @Autowired
    private PestsControlService pestsControlService;

    @Autowired
    private PestsTrapService pestsTrapService;
    //     0/5 * * * * ?表示每隔5秒执行一次这个方法
    @Scheduled(cron = "0 0 1 * * ?")
    public void task1() {
        System.out.println("**************task1执行了..");
        List<PestsProject> projects = service.list();
        for (PestsProject pp :
                projects) {
            Integer count = pestsControlService.countPestsByProjectId(pp.getId());
            Integer scount = pestsTrapService.countTrapByProjectId(pp.getId());
            pp.setRecordCount(count);
            pp.setEntities(scount);
            pp.setFileCount((count+scount) * 2);
            pp.setDeskCount(pp.getFileCount() * 1200);
            service.updateById(pp);
        }

    }
}
